

import com.sap.smb.sbo.api.ICompany;
import com.sap.smb.sbo.api.SBOCOMConstants;
import com.sap.smb.sbo.api.SBOCOMUtil;
import com.sap.smb.sbo.api.SBOErrorMessage;


/**
 * Created by IntelliJ IDEA.
 * User: mlv
 * Date: 2013-2-19
 * Time: 16:19:08
 * To change this template use File | Settings | File Templates.
 */
public class JcoConn{

     public static void main(String[] args) {

          JcoConn company = new JcoConn();

          company.conn();

     }

     //method make connection andinitialize company instance

     public static ICompany conn() {
         ICompany company = null;
          try {
               company = SBOCOMUtil.newCompany();
               company.setServer("MLV-HP");
               company.setCompanyDB("SBODemoUS");
               company.setUserName("manager");
               company.setPassword("manager");
               company.setDbServerType(SBOCOMConstants.BoDataServerTypes_dst_MSSQL2008);
               company.setUseTrusted(new Boolean(false));
               company.setLanguage(SBOCOMConstants.BoSuppLangs_ln_English);
               company.setDbUserName("sa");
               company.setDbPassword("huihe");

               int rc = company.connect();
               if (rc == 0) {
                    System.out.println("Connected!");
               } else {
                    SBOErrorMessage errMsg = company.getLastError();
                    System.out.println(
                         "I cannot connect to database server: "
                              + errMsg.getErrorMessage()
                              + " "
                              + errMsg.getErrorCode());
               }



          } catch (Exception e) {
               e.printStackTrace();
               return null;

          }
          return company;
     }

 }
